
const Controller = require('../../core/Controller');
const query = require('../../core/db');


class otherController extends Controller {
  constructor() {
    super();
  }
  async getTime(ctx) {
    ctx.response.body = new Date().getTime();
  }

  async getOtherList(ctx) {
    let sql = 'select * from other where 1=1';
    let values = [];
    ctx.response.body = await query(sql, values).then( results => { return results; });
  }

  async editOther(ctx) {
    const { o_id, o_content } = ctx.request.body || ctx.request.query;
    let sql = `update other set o_content=? where o_id=?`;
    let values = [ o_content, o_id ];
    try {
      let res = await query(sql, values).then( results => { return results; });
      console.log(res);
      ctx.response.body =  true;
    } catch (e) {
      console.log('e', e);
      ctx.response.body =  false;
    }

  }
}

module.exports = new otherController;
